#ifndef _PPU_H
#define _PPU_H

#include "type.h"
#include "nes_config.h"

class CNes;
class CPpu
{
public:
        CPpu(CNes* nes);
        ~CPpu();

public:
  void  Reset();
  void  Stop();

  void  FrameStart();
  void  VBlankStart();
  void  VBlankEnd();

  void  Scroll(u8 coord);
  void  SetAddress(u8 addr);
  void  WriteVRam(u8 data);
  u8    ReadVRam();
  void  SetSprAddr(u8 addr);
  void  WriteSprRam(u8 data);
  u8    ReadSprRam();
  void  SprDMA(u8* data);

  void  SetNameTblBank(bool v);

public:
  /*
    PPU Memory Map (14bit buswidth, 0-3FFFh)
      0000h-0FFFh   Pattern Table 0 (4K) (256 Tiles)
      1000h-1FFFh   Pattern Table 1 (4K) (256 Tiles)
      2000h-23FFh   Name Table 0 and Attribute Table 0 (1K) (32x30 BG Map)
      2400h-27FFh   Name Table 1 and Attribute Table 1 (1K) (32x30 BG Map)
      2800h-2BFFh   Name Table 2 and Attribute Table 2 (1K) (32x30 BG Map)
      2C00h-2FFFh   Name Table 3 and Attribute Table 3 (1K) (32x30 BG Map)
      3000h-3EFFh   Mirror of 2000h-2EFFh
      3F00h-3F1Fh   Background and Sprite Palettes (25 entries used)
      3F20h-3FFFh   Mirrors of 3F00h-3F1Fh
  */
  u8      PPU_MEM[16 * 1024];
  u8*     PatternTable[2];
  u8*     NameTable[4];
  u8*     AttribTable[4];
  u8*     BGPalettes;
  u8*     SPPalettes;

  /*
    SPR-RAM Memory Map (8bit buswidth, 0-FFh)
      00-FF   Sprite Attributes (256 bytes, for 64 sprites / 4 bytes each)
  */
  u8      SprRam[0x100];

  // register
  u8      Register[8];
  bool    m_IsLowAddress;
  u16     m_RamAddress;
  u8      m_SprRamAddr;
  u8      m_Reg2007Val;

  // Scrolling coord
  int     m_OfsX, m_OfsY;

private:
  CNes*   m_NES;
};

#endif  // _PPU_H
